/*
 * @Author: 刘岩 15136056318@163.com
 * @Date: 2023-11-11 10:55:35
 * @LastEditors: LiuYan 15136056318@163.com
 * @LastEditTime: 2023-12-01 17:44:59
 * @FilePath: \react-template_pc\src\hooks\utils.ts
 * @Description: 针对hooks封装常调用的公共方法
 */
import type { RouterParamsType } from './data'

/**
 * @description:  query对象转字符串
 * @param {string} params
 * @return {*}
 */
export const queryToString = (params: string | RouterParamsType): string => {
  let paramsTemp: string = ''
  // 判断参数是否是字符串
  if (typeof params == 'string') {
    paramsTemp += params
  } else {
    paramsTemp += params.path
    // 针对query对象进行转字符串
    if (params?.query) {
      const query = params.query
      Object.keys(query).forEach((key, index) => {
        index === 0 ? (paramsTemp += `?`) : (paramsTemp += `&`)
        paramsTemp += `${key}=${query[key]}`
      })
    }
  }
  return paramsTemp
}
